import os
import time
import pytest
from common.Assert import Assert
from common.readData import readData
from common import loginOperater
from common.serviceWeb import ServiceWeb

read_data=readData()

class Testlogin:
    @pytest.mark.parametrize("username,password,expect", read_data.read_data(0,3))
    def test_success_login(self,username,password,expect):
        #拉起浏览器
        service = ServiceWeb()
        chromeDriver = service.get_driver("http://localhost:90/")
        #登录
        login=loginOperater.LoginOperater()
        login.login(chromeDriver,username,password)
        time.sleep(1)

        #判断、截图
        result = chromeDriver.title
        screenshot_dir = "D:\pythonproject\自动化_1封装\失败截图\successlogin"
        screenshot_path = f"{screenshot_dir}/{username}失败截图.png"

        Assert(chromeDriver,result,expect,screenshot_path)
        chromeDriver.quit()

    @pytest.mark.parametrize("username,password,expect", read_data.read_data(1, 3))
    def test_defeat_login(self, username, password, expect):
        # 拉起浏览器
        service = ServiceWeb()
        chromeDriver = service.get_driver("http://localhost:90/")
        # 登录
        login = loginOperater.LoginOperater()
        login.login(chromeDriver, username, password)
        time.sleep(1)

        # 判断
        result = chromeDriver.title
        screenshot_dir = "D:\pythonproject\自动化_1封装\失败截图\defeatlogin"
        screenshot_path = f"{screenshot_dir}/{username}失败截图.png"
        Assert(chromeDriver,result,expect,screenshot_path)

        chromeDriver.quit()